package com.my.ecommercesystem.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.my.ecommercesystem.dao.GoodsDao;
import com.my.ecommercesystem.entity.Goods;
import com.my.ecommercesystem.dto.GoodsDto;
import com.my.ecommercesystem.entity.Goods;
import com.my.ecommercesystem.service.GoodsService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class GoodsServiceImpl implements GoodsService {
    @Resource
    private GoodsDao goodsDao;

    public GoodsDao getGoodsDao() {
        return goodsDao;
    }

    public void setGoodsDao(GoodsDao goodsDao) {
        this.goodsDao = goodsDao;
    }

    @Override
    public List<Goods> findOneType(Integer type_id) {
        return goodsDao.querySingleTypeGoodsByType(type_id);
    }

    @Override
    public Goods queryGoodsByGoodsId(Integer id) {
        if (id!=null){
            return goodsDao.queryGoodsByGoodsId(id);
        }
        return null;
    }

    @Override
    public Page<GoodsDto> queryGoods(GoodsDto goods,Integer page,Integer size) {
        PageHelper.startPage(page,size);
        Page<GoodsDto> list=goodsDao.queryGoods(goods);
        return list;
    }

    @Override
    public Long queryGoodsCount(GoodsDto goods) {

        return goodsDao.queryGoodsCount(goods);
    }

    @Override
    public Page<GoodsDto> queryGoodsByTime(Integer page, Integer size) {
        PageHelper.startPage(page,size);
        Page<GoodsDto> list=goodsDao.queryGoodsByTime();
        return list;
    }

    @Override
    public Page<GoodsDto> queryGoodsByKey(String key,  Integer page, Integer size) {
        PageHelper.startPage(page,size);
        Page<GoodsDto> list=goodsDao.queryGoodsByKey(key);
        return list;
    }

    @Override
    public Long queryGoodsCountByKey(String key) {
        return goodsDao.queryGoodsCountByKey(key);
    }
}
